﻿using System;

namespace YinfangWeb.BLL.Enum
{
    /// <summary>
    /// 错误代码
    /// 规则：5位
    /// 0：成功；-1：系统繁忙
    /// </summary>
    public enum ResultCode
    {
        #region 登录账号相关 2开头
        /// 登录成功
        /// </summary>
        AccountLoginSuccess = 20000,

        /// <summary>
        /// 登录失败
        /// </summary>
        AccountLoginFail = 20001,

        /// <summary>
        /// 缺少Token
        /// </summary>
        AccountTokenMissing = 20010,

        /// <summary>
        /// Token验证失效
        /// </summary>
        AccountTokenError = 20011,

        /// <summary>
        /// 缺少登录项
        /// </summary>
        AccountParameterMissing = 20009,

        /// <summary>
        /// 密保验证失败
        /// </summary>
        AccountSecurityValidFailture = 20023,

        /// <summary>
        /// 帐号注册失败
        /// </summary>
        AccountRegistError = 21001,

        /// <summary>
        /// 帐号登录错误（用户名或密码错误）
        /// </summary>
        AccountLoginError = 21004,

        /// <summary>
        /// 未找到用户
        /// </summary>
        AccountUserNotFound = 21005,

        /// <summary>
        /// 帐号异常
        /// </summary>
        AccountException = 21009,

        /// <summary>
        /// 用户手机号码为空
        /// </summary>
        AccountUserEmptyMobile = 21011,
        #endregion

        #region 通用信息 1开头
            /// <summary>
            /// 成功
            /// </summary>
            Success = 0,

            /// <summary>
            /// 系统繁忙
            /// </summary>
            Busy = -1,

            /// <summary>
            /// 缺少Token
            /// </summary>
            TokenMissing = 10000,

            /// <summary>
            /// Token验证失效
            /// </summary>
            TokenError = 10001,

            /// <summary>
            /// 缺少参数
            /// </summary>
            ParameterMissing = 10002,
        
            /// <summary>
            /// 参数错误
            /// </summary>
            ParameterError = 10003,

            /// <summary>
            /// 超出索引范围
            /// </summary>
            IndexOutOfRange = 10004,

            /// <summary>
            /// 记录已存在
            /// </summary>
            RecordExist = 10005,

            /// <summary>
            /// 记录不存在
            /// </summary>
            RecordNotExist = 10006,

            /// <summary>
            /// 字段不能为空
            /// </summary>
            FieldCannotEmpty = 10007,

            /// <summary>
            /// 文件上传失败
            /// </summary>
            FileUploadFailed = 10010,

            /// <summary>
            /// 没有权限
            /// </summary>
            NoPermission = 10011,

            /// <summary>
            /// 无法执行此操作
            /// </summary>
            CanNotPerform = 10012,

            /// <summary>
            /// 不合法的操作
            /// </summary>
            ActionNotExist = 10013,

            /// <summary>
            /// 已失效的操作
            /// </summary>
            ActionNotValid = 10014,

            /// <summary>
            /// 该操作已完成
            /// </summary>
            ActionHasCompleted = 10015,

            /// <summary>
            /// API调用未授权
            /// </summary>
            ApiNotPermission = 10022,
        
            /// <summary>
            /// 未知来源
            /// </summary>
            UnknownUserIdentity = 11006,

            /// <summary>
            /// 姓名被锁定（不能修改）
            /// </summary>
            RealNameLocked = 11008,

            /// <summary>
            /// 列表为空
            /// </summary>
            ListIsEmpty=20000,
        #endregion
    }

    public static class ResultCodeExtension
    {
        public static string GetMsg(this ResultCode code)
        {
            var Msg = string.Empty;
            switch (code)
            {
                #region 登录账号相关
                case ResultCode.AccountLoginSuccess:
                    Msg = "登录成功";
                    break;
                case ResultCode.AccountLoginFail:
                    Msg = "登录失败";
                    break;
                case ResultCode.AccountTokenMissing:
                    Msg = "缺少Token";
                    break;
                case ResultCode.AccountTokenError:
                    Msg = "Token验证失效";
                    break;
                case ResultCode.AccountParameterMissing:
                    Msg = "缺少登录项";
                    break;

                case ResultCode.AccountSecurityValidFailture:
                    Msg = "密保验证失败";
                    break;
                case ResultCode.AccountRegistError:
                    Msg = "帐号注册失败";
                    break;
                case ResultCode.AccountLoginError:
                    Msg = "帐号登录错误（用户名或密码错误）";
                    break;
                case ResultCode.AccountUserNotFound:
                    Msg = "未找到用户";
                    break;
                case ResultCode.AccountException:
                    Msg = "帐号异常";
                    break;
                case ResultCode.AccountUserEmptyMobile:
                    Msg = "用户手机号码为空";
                    break;
                #endregion
                case ResultCode.Success:
                    Msg = "success";
                    break;
                case ResultCode.Busy:
                    Msg = "系统繁忙";
                    break;
                case ResultCode.TokenMissing:
                    Msg = "缺少登录信息，请重新登录";
                    break;
                case ResultCode.TokenError:
                    Msg = "登录信息过期，请重新登录";
                    break;
                case ResultCode.ApiNotPermission:
                    Msg = "API调用未授权";
                    break;
                case ResultCode.ParameterMissing:
                    Msg = "缺少参数";
                    break;
                case ResultCode.ParameterError:
                    Msg = "参数错误";
                    break;
                case ResultCode.IndexOutOfRange:
                    Msg = "超出索引范围";
                    break;
                case ResultCode.RecordExist:
                    Msg = "记录已存在";
                    break;
                case ResultCode.RecordNotExist:
                    Msg = "记录不存在";
                    break;
                case ResultCode.FieldCannotEmpty:
                    Msg = "字段为空";
                    break;

                case ResultCode.FileUploadFailed:
                    Msg = "文件上传失败";
                    break;
                case ResultCode.NoPermission:
                    Msg = "没有权限";
                    break;
                case ResultCode.CanNotPerform:
                    Msg = "无法执行此操作";
                    break;
                case ResultCode.UnknownUserIdentity:
                    Msg = "未知来源";
                    break;
                case ResultCode.ActionNotExist:
                    Msg = "不合法的操作";
                    break;
                case ResultCode.ActionNotValid:
                    Msg = "已失效的操作";
                    break;
                case ResultCode.ActionHasCompleted:
                    Msg = "该操作已完成";
                    break;
                case ResultCode.RealNameLocked:
                    Msg = "姓名被锁定";
                    break;
            }
            return Msg;
        }
    }
}
